-- arm_villager_upgrade
-- create by zhuangsl
-- 附加属性：武装村民升级装备

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 武装村民触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_USER then
            return;
        end

        -- 已武装数量增加
        DungeonServiceM.addDungeonAttrib("arm_villagers", 1);

        -- 如果数量还未满
        if DungeonServiceM.queryDungeonAttrib("arm_villagers") < prop[3] then
            return;
        end

        -- 先扣除
        DungeonServiceM.costDungeonAttrib({["arm_villagers"] = prop[3], });

        -- 转换一下装备
        local arr = string.explode(prop[2], "~");
        EquipM.transformEquipment(tonumber(arr[1]), tonumber(arr[2]));
        
        -- 装备升级的事件
        EventMgr.fire(event.UPGRADE_EQUIP, {["classId"] = tonumber(arr[1]), ["delay"] = 2; });
        
        return true;
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;
        local count = DungeonServiceM.queryDungeonAttrib("arm_villagers");

        desc = string.gsub(desc, "{0}", tonumber(count));
        desc = string.gsub(desc, "{1}", prop[3]);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};
